//
//  ZFCustomControlView.m
//  ZFPlayer_Example
//
//  Created by 紫枫 on 2019/6/5.
//  Copyright © 2019 紫枫. All rights reserved.
//
#define defaultBtn_w 70

#import "MoreCoverView.h"
#import "UIButton+offsetIMG.h"
@interface MoreCoverView ()
/// 加入授课包
//@property (nonatomic, strong) UIButton *addBtn;
@end

@implementation MoreCoverView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {

    [self addAllSubViews];
        /// statusBarFrame changed
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layoutControllerViews) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat min_margin = 9;
    CGFloat btn_w = defaultBtn_w;
    CGFloat btn_H = 40;
    CGFloat min_view_w = self.bounds.size.width;
    CGFloat min_view_h = self.bounds.size.height;
    
    self.BGView.frame = CGRectMake(0, 0, min_view_w, min_view_h);
    self.addBtn.frame = CGRectMake(min_margin, 40, btn_w, btn_H);
    self.shareBtn.frame = CGRectMake(CGRectGetMaxX(self.addBtn.frame) + min_margin, CGRectGetMinY(self.addBtn.frame), btn_w, btn_H);
    self.recommendBtn.frame = CGRectMake(CGRectGetMaxX(self.shareBtn.frame) + min_margin, CGRectGetMinY(self.shareBtn.frame), btn_w, btn_H);

    /// 亮度滑杆
    self.brightSlider.frame = CGRectMake(min_margin, CGRectGetMaxY(self.addBtn.frame) + btn_H, min_view_w - (min_margin *2), 40);
    /// 音量滑杆
    self.volumeSlider.frame = CGRectMake(min_margin, CGRectGetMaxY(self.brightSlider.frame) + btn_H, min_view_w - (min_margin *2), 40);
}

- (void)layoutControllerViews {
    [self layoutIfNeeded];
    [self setNeedsLayout];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}

/// 添加所有子控件
- (void)addAllSubViews {
    [self addSubview:self.BGView];
    [self addSubview:self.addBtn];
    [self addSubview:self.shareBtn];
    [self addSubview:self.recommendBtn];
    [self addSubview:self.brightSlider];
    [self addSubview:self.volumeSlider];

    [self.brightSlider showViewLeftIcon:@"icon_bright-" rightIcon:@"icon_bright+"];
    [self.volumeSlider showViewLeftIcon:@"icon_volume-" rightIcon:@"icon_volume-"];
//    [self addSubview:self.landScapeControlView];
//    [self addSubview:self.floatControlView];
//    [self addSubview:self.activity];
//    [self addSubview:self.failBtn];
//    [self addSubview:self.fastView];
//    [self.fastView addSubview:self.fastImageView];
//    [self.fastView addSubview:self.fastTimeLabel];
//    [self.fastView addSubview:self.fastProgressView];
//    [self addSubview:self.bottomPgrogress];
//    [self addSubview:self.volumeBrightnessView];
}

- (UIView *)BGView {
    if (!_BGView) {
        _BGView = [[UIView alloc] init];
        _BGView.backgroundColor = [UIColor blackColor];
        _BGView.alpha = 0.65;
    }
    return _BGView;
}
- (UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_addBtn addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];


        UIImageView * upImg = [[UIImageView  alloc] initWithFrame:CGRectMake((defaultBtn_w - 20)/2, 0, 20, 20)];
        upImg.image = UXUtilities_Image(@"icon_add");
        [_addBtn addSubview: upImg];

        UILabel *content = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, defaultBtn_w, 20)];
        content.text = @"加入授课";
        content.font = [UIFont systemFontOfSize:10];
        content.textColor = [UIColor whiteColor];
        content.textAlignment = NSTextAlignmentCenter;
        [_addBtn addSubview: content];

    }
    return _addBtn;
}
- (UIButton *)shareBtn {
    if (!_shareBtn) {
        _shareBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        UIImageView * upImg = [[UIImageView  alloc] initWithFrame:CGRectMake((defaultBtn_w - 20)/2, 0, 20, 20)];
        upImg.image = UXUtilities_Image(@"icon_share");
        [_shareBtn addSubview: upImg];

        UILabel *content = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, defaultBtn_w, 20)];
        content.text = @"分享";
        content.font = [UIFont systemFontOfSize:10];
        content.textColor = [UIColor whiteColor];
        content.textAlignment = NSTextAlignmentCenter;
        [_shareBtn addSubview: content];
    }
    return _shareBtn;
}
- (UIButton *)recommendBtn {
    if (!_recommendBtn) {
        _recommendBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [_recommendBtn addTarget:self action:@selector(recommendBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        UIImageView * upImg = [[UIImageView  alloc] initWithFrame:CGRectMake((defaultBtn_w - 20)/2, 0, 20, 20)];
        upImg.image = UXUtilities_Image(@"icon_ recommend");
        [_recommendBtn addSubview: upImg];

        UILabel *content = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, defaultBtn_w, 20)];
        content.text = @"推荐";
        content.font = [UIFont systemFontOfSize:10];
        content.textColor = [UIColor whiteColor];
        content.textAlignment = NSTextAlignmentCenter;
        [_recommendBtn addSubview: content];
    }
    return _recommendBtn;
}
- (SliderView_icon *)brightSlider {
    if (!_brightSlider) {
        _brightSlider = [[SliderView_icon alloc] init];
    }
    return _brightSlider;
}
- (SliderView_icon *)volumeSlider {
    if (!_volumeSlider) {
        _volumeSlider = [[SliderView_icon alloc] init];
    }
    return _volumeSlider;
}

-(void)addBtnClick:(UIButton  *)sender {
    if (self.addBlock != nil) {
        self.addBlock();
    }
}
-(void)shareBtnClick:(UIButton  *)sender {
    if (self.shareBlock != nil) {
        self.shareBlock();
    }
}
-(void)recommendBtnClick:(UIButton  *)sender {
    if (self.recommendBlock != nil) {
        self.recommendBlock();
    }
}
- (void)setBrightSliderBlock:(SliderValueChangingBlock )newClickCallback {
    _brightSliderBlock = [newClickCallback copy];
    self.brightSlider.sliderBlock = _brightSliderBlock;
}
- (void)setVolumeSliderBlock:(SliderValueChangingBlock )newClickCallback {
    _volumeSliderBlock = [newClickCallback copy];
    self.volumeSlider.sliderBlock = _volumeSliderBlock;
}
@end
